﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BL;
using IUI;
using BaseUI;
using Data;

namespace WinUI
{
    public partial class LoginForm : //Form
                                     BaseWinForm<LoginController>, ILogin
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private event EventHandler _click_LoginButton;

        private void btn_Login_Click(object sender, EventArgs e)
        {
            if (_click_LoginButton != null) _click_LoginButton(this, null);
        }

        #region Члены ILogin

        public String strLogin
        {
            get { 
                return txtBx_Login.Text; 
            }
        }
               
        public String strPasswd
        {
            get {
                return txtBx_Passwd.Text; 
            }
        }

        public EventHandler Click_LoginButton
        {
            get { return _click_LoginButton; }
            set { _click_LoginButton = value; }
        }

        public void ShowError(bool empty)
        {
            if (empty)
            {
                MessageBox.Show("Login & Password fields shouldn't be empty",
                                "Input Error",
                                MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("Check Login and Password", "Login State", MessageBoxButtons.OK);
            }
        }

        #endregion

        private void txtBx_Login_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar == '\r')
            {
                this.btn_Login_Click(this, new EventArgs());
            }
        }

        private void txtBx_Passwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.btn_Login_Click(this, new EventArgs());
            }
        }

    }
}
